package jvm.ref;

import java.lang.ref.WeakReference;

/**
 * 弱引用
 * @author jiangwz
 * @create 2019/9/17.
 */
public class WeakReferenceDemo {


    /**
     * 弱引用不管内存够不够,全部回收
     * @param args
     */
    public static void main(String[] args){

        Object o1 = new Object();
        WeakReference<Object> weakReference = new WeakReference<>(o1);
        System.out.println(o1);
        System.out.println(weakReference.get());

        o1 = null;
        System.gc();
        System.out.println(o1);
        System.out.println(weakReference.get());
    }
}
